
<h1><span class="yiyi-st" id="yiyi-13">numpy.ma.median</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.median.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.median.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.ma.median"><span class="yiyi-st" id="yiyi-14"> <code class="descclassname">numpy.ma.</code><code class="descname">median</code><span class="sig-paren">(</span><em>a</em>, <em>axis=None</em>, <em>out=None</em>, <em>overwrite_input=False</em>, <em>keepdims=False</em><span class="sig-paren">)</span><a class="reference external" href="http://github.com/numpy/numpy/blob/v1.11.3/numpy/ma/extras.py#L563-L643"><span class="viewcode-link">[source]</span></a></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-15">计算沿指定轴的中值。</span></p>
<p><span class="yiyi-st" id="yiyi-16">返回数组元素的中位数。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-17">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-18"><strong>a</strong>：array_like</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-19">输入可以转换为数组的数组或对象。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-20"><strong>axis</strong>：int，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-21">计算中值的轴。</span><span class="yiyi-st" id="yiyi-22">默认值（None）用于计算数组的扁平版本的中值。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-23"><strong>out</strong>：ndarray，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-24">用于放置结果的替代输出数组。</span><span class="yiyi-st" id="yiyi-25">它必须具有与预期输出相同的形状和缓冲区长度，但如果需要，将转换类型。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-26"><strong>overwrite_input</strong>：bool，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-27">如果为True，则允许使用输入数组（a）的内存进行计算。</span><span class="yiyi-st" id="yiyi-28">输入数组将通过对中值的调用进行修改。</span><span class="yiyi-st" id="yiyi-29">当您不需要保留输入数组的内容时，这将节省内存。</span><span class="yiyi-st" id="yiyi-30">将输入视为未定义，但可能会完全或部分排序。</span><span class="yiyi-st" id="yiyi-31">默认值为False。</span><span class="yiyi-st" id="yiyi-32">请注意，如果<em class="xref py py-obj">overwrite_input</em>为True，并且输入不是<em class="xref py py-obj">ndarray</em>，则会引发错误。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-33"><strong>keepdims</strong>：bool，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-34">如果设置为True，则缩小的轴在结果中保留为尺寸为1的尺寸。</span><span class="yiyi-st" id="yiyi-35">使用此选项，结果将根据输入数组正确地广播。</span></p>
<div class="versionadded">
<p><span class="yiyi-st" id="yiyi-36"><span class="versionmodified">版本1.10.0中的新功能。</span></span></p>
</div>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-37">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-38"><strong>median</strong>：ndarray</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-39">除非指定了out，否则将返回保存结果的新数组，在这种情况下将返回对out的引用。</span><span class="yiyi-st" id="yiyi-40">对于小于<em class="xref py py-obj">float64</em>的整数和浮点型，返回数据类型为<em class="xref py py-obj">float64</em>，否则为输入数据类型。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-41">也可以看看</span></p>
<p class="last"><span class="yiyi-st" id="yiyi-42"><a class="reference internal" href="numpy.ma.mean.html#numpy.ma.mean" title="numpy.ma.mean"><code class="xref py py-obj docutils literal"><span class="pre">mean</span></code></a></span></p>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-43">笔记</span></p>
<p><span class="yiyi-st" id="yiyi-44">Given a vector <code class="docutils literal"><span class="pre">V</span></code> with <code class="docutils literal"><span class="pre">N</span></code> non masked values, the median of <code class="docutils literal"><span class="pre">V</span></code> is the middle value of a sorted copy of <code class="docutils literal"><span class="pre">V</span></code> (<code class="docutils literal"><span class="pre">Vs</span></code>) - i.e. <code class="docutils literal"><span class="pre">Vs[(N-1)/2]</span></code>, when <code class="docutils literal"><span class="pre">N</span></code> is odd, or <code class="docutils literal"><span class="pre">{Vs[N/2</span> <span class="pre">-</span> <span class="pre">1]</span> <span class="pre">+</span> <span class="pre">Vs[N/2]}/2</span></code> when <code class="docutils literal"><span class="pre">N</span></code> is even.</span></p>
<p class="rubric"><span class="yiyi-st" id="yiyi-45">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ma</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">8</span><span class="p">),</span> <span class="n">mask</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="mi">4</span> <span class="o">+</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">ma</span><span class="o">.</span><span class="n">median</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">1.5</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ma</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">mask</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="mi">6</span> <span class="o">+</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">ma</span><span class="o">.</span><span class="n">median</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">2.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">ma</span><span class="o">.</span><span class="n">median</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">,</span> <span class="n">overwrite_input</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">masked_array(data = [ 2.  5.],</span>
<span class="go">             mask = False,</span>
<span class="go">       fill_value = 1e+20)</span>
</pre></div>
</div>
</dd></dl>
